﻿using Aspfm.Main;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web;

namespace Aspfm.MainController
{
    public class PageTool
    {
        public static string GetWebBaseUrl()
        {
            return Aspfm.Main.PageTool.GetWebBaseUrl();
        }
        public static string GetAspfmConfig(string typename, string keystr)
        {
            return Aspfm.Main.PageTool.GetAspfmConfig(typename, keystr);
        }
        public static string GetWebConfig(string keystr)
        {
            return Aspfm.Main.PageTool.GetWebConfig(keystr); 
        }
        public static string LinkFile(string file)
        {
            return Aspfm.Main.PageTool.LinkFile(file);  
        }
        public static string GetUrl(string url)
        {
            return GetWebBaseUrl() + url;
        }

        public string GetAspxPage()
        {
            return Aspfm.Main.PageTool.GetAspxPage();  
        }
        public static System.Diagnostics.Stopwatch GetAspxStartTime()
        {
            return Aspfm.Main.PageTool.GetAspxStartTime();  
        }
        public static string GetAspxLoadTime(System.Diagnostics.Stopwatch swpage)
        {
            return Aspfm.Main.PageTool.GetAspxLoadTime(swpage);  
        }
        public static string GetAspxParamsAll()
        {
            return Aspfm.Main.PageTool.GetAspxParamsAll();  
        }
        public static string GetAspxParamsRemove(params string[] paramKey)
        {
            return Aspfm.Main.PageTool.GetAspxParamsRemove(paramKey);  
        }

        public static string GetAspx(string aspx)
        {
            return Aspfm.Main.PageTool.GetAspx(aspx);   
        }
        public static bool CheckLogin()
        {
            return Aspfm.Main.PageTool.CheckLogin();   
        }
        /// <summary>
        /// 检查是否有访问站点权限。
        /// 可以自由定义过滤规则
        /// </summary>
        /// <returns></returns>
        public static bool CheckRole()
        {
            return Aspfm.Main.PageTool.CheckRole();   
        }

        public static void BeginRequestLogin()
        {
            Aspfm.Main.PageTool.BeginRequestLogin();    
        }
        public static void WriteLog(Exception ex)
        {
            Aspfm.Main.Loger.WriteLog(ex);
        }
        public static void WriteLog(string Msg, string objid = "", bool asynchronous = true)
        {
            Aspfm.Main.Loger.WriteLog(LogType.WebApp, Msg, objid, asynchronous);
        }
        public static void CheckAspfm()
        {
            Aspfm.Html.AspfmHtml.CheckAspfm();
        }
        public static void InitConn()
        {
            System.Threading.ThreadPool.QueueUserWorkItem(delegate { Aspfm.Dal.DbTool.InitConn(); });
        }
        public static void AspfmRequest(HttpContext context)
        {
            BaseAshx.AspfmRequest(context);
        }
        public static string GetAspfmQueryJs()
        {
            if (System.Web.HttpContext.Current != null)
            {
                if (!string.IsNullOrEmpty(System.Web.HttpContext.Current.Request.Url.Query))
                {
                    StringBuilder sbjs = new StringBuilder();
                    foreach (string str in System.Web.HttpContext.Current.Request.QueryString.AllKeys)
                    {
                        if (!string.IsNullOrEmpty(str))
                        {
                            sbjs.AppendLine("Aspfm.Data.Url.url" + str + "='" + System.Web.HttpContext.Current.Request.QueryString[str] + "';");
                        }
                    }
                    return sbjs.ToString().Trim();
                }
            }
            return "";
        }
    }
}
